﻿package Welsy4.Connect.commands {
	import com.adobe.cairngorm.commands.SequenceCommand;
	import flash.net.URLVariables;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.IResponder;
	import mx.controls.Alert;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import Welsy4.Connect.business.PermissionDelegate;
	import Welsy4.Connect.events.ChainEvent;
	import Welsy4.Connect.events.ResponseEvent;
	import Welsy4.Connect.model.ConnectModel;
	import Welsy4.Connect.vo.HttpServiceHandler;
	import Welsy4.Connect.vo.Meeting;

	public class SetMeetingPrivateCommand extends SequenceCommand implements Command, IResponder {

		override public function execute(event : CairngormEvent) : void {
			ConnectModel.getInstance().addQueue("SetMeetingPrivateCommand.execute ");
			this.nextEvent = ChainEvent(event).nextChainedEvent;
			var publicPermissionRequest : URLVariables = new URLVariables();

			// set request GET params
			publicPermissionRequest.action = "permissions-update";
			publicPermissionRequest.decode("acl-id=" + ConnectModel.getInstance().SCOShortcutRequested.sco_id);
			publicPermissionRequest.decode("principal-id=public-access");
			publicPermissionRequest.decode("permission-id=denied");

			// set Delegate to send data
			var permissionDelegate : PermissionDelegate = new PermissionDelegate(this);
			permissionDelegate.setPermission(publicPermissionRequest);
		}

		public function result(event : Object) : void {

			// listen for ok result
			//AG eliminato!!
			/*  CairngormEventDispatcher.getInstance().dispatchEvent(new ResponseEvent(ResponseEvent.MEETING_CREATED,true,ResponseEvent.OK, event.result)); */
			ConnectModel.getInstance().addQueue("SetMeetingPrivateCommand.result " + event.result);
			this.executeNextCommand();
		}

		public function fault(event : Object) : void {
			ConnectModel.getInstance().addQueue("SetMeetingPublicCommand.fault");
			CairngormEventDispatcher.getInstance().dispatchEvent(new ResponseEvent(ResponseEvent.ERROR, false, ResponseEvent.CONNECTION));
		}
	}

}